<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "major".
 *
 * @property int $ID ID
 * @property int $XXID 学校ID
 * @property int|null $BMID 部门院系ID
 * @property string $ZYDM 专业代码
 * @property string $ZYMC 专业名称
 * @property string $ZYJC 专业简称
 * @property string $BXZYBH 本校专业编号
 * @property string $PYFA 培养方案
 * @property string|null $ZYJS 专业介绍
 * @property string $KSSJ 开设时间
 * @property string|null $CXSJ 撤销时间
 * @property string $ZYMLBB 专业目录版本
 * @property string $ZYLB 专业类别
 * @property string $ZYFX 专业方向
 * @property string $ZSLB 招生类别
 * @property string $XZ 学制
 * @property string $JXXS 教学形式
 * @property float $ZXF 总学分
 * @property float $BXXF 必修学分
 * @property string $SFGK 是否国控
 * @property string $SFSN 是否涉农专业
 * @property string $ZSZG 招生资格
 * @property string $ZT 状态
 *
 * @property Clazz[] $clazzs
 * @property School $xX
 * @property Department $bM
 * @property MajorCourse[] $majorCourses
 * @property Course[] $kCs
 * @property Teacher[] $teachers
 */
class Major extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'major';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XXID', 'ZYDM', 'ZYMC', 'ZYJC', 'BXZYBH', 'PYFA', 'KSSJ', 'ZYMLBB', 'ZYLB', 'ZYFX', 'ZSLB', 'XZ', 'JXXS', 'ZXF', 'BXXF', 'SFGK', 'SFSN', 'ZSZG', 'ZT'], 'required'],
            [['XXID', 'BMID'], 'integer'],
            [['ZYJS'], 'string'],
            [['KSSJ', 'CXSJ'], 'safe'],
            [['ZXF', 'BXXF'], 'number'],
            [['ZYDM', 'ZYJC', 'BXZYBH', 'ZYMLBB'], 'string', 'max' => 20],
            [['ZYMC', 'ZYLB', 'ZYFX'], 'string', 'max' => 50],
            [['PYFA'], 'string', 'max' => 100],
            [['ZSLB', 'XZ', 'JXXS', 'SFGK', 'SFSN', 'ZSZG', 'ZT'], 'string', 'max' => 10],
            [['XXID'], 'exist', 'skipOnError' => true, 'targetClass' => School::className(), 'targetAttribute' => ['XXID' => 'ID']],
            [['BMID'], 'exist', 'skipOnError' => true, 'targetClass' => Department::className(), 'targetAttribute' => ['BMID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XXID' => '学校ID',
            'BMID' => '部门院系ID',
            'ZYDM' => '专业代码',
            'ZYMC' => '专业名称',
            'ZYJC' => '专业简称',
            'BXZYBH' => '本校专业编号',
            'PYFA' => '培养方案',
            'ZYJS' => '专业介绍',
            'KSSJ' => '开设时间',
            'CXSJ' => '撤销时间',
            'ZYMLBB' => '专业目录版本',
            'ZYLB' => '专业类别',
            'ZYFX' => '专业方向',
            'ZSLB' => '招生类别',
            'XZ' => '学制',
            'JXXS' => '教学形式',
            'ZXF' => '总学分',
            'BXXF' => '必修学分',
            'SFGK' => '是否国控',
            'SFSN' => '是否涉农专业',
            'ZSZG' => '招生资格',
            'ZT' => '状态',
        ];
    }

    /**
     * Gets query for [[Clazzs]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getClazzs()
    {
        return $this->hasMany(Clazz::className(), ['ZYID' => 'ID'])->inverseOf('zY');
    }

    /**
     * Gets query for [[XX]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXX()
    {
        return $this->hasOne(School::className(), ['ID' => 'XXID'])->inverseOf('majors');
    }

    /**
     * Gets query for [[BM]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getBM()
    {
        return $this->hasOne(Department::className(), ['ID' => 'BMID'])->inverseOf('majors');
    }

    /**
     * Gets query for [[MajorCourses]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getMajorCourses()
    {
        return $this->hasMany(MajorCourse::className(), ['ZYID' => 'ID'])->inverseOf('zY');
    }

    /**
     * Gets query for [[KCs]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getKCs()
    {
        return $this->hasMany(Course::className(), ['ID' => 'KCID'])->viaTable('major_course', ['ZYID' => 'ID']);
    }

    /**
     * Gets query for [[Teachers]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getTeachers()
    {
        return $this->hasMany(Teacher::className(), ['ZYID' => 'ID'])->inverseOf('zY');
    }
}
